package com.example.lj.uav.utils;

import android.text.TextUtils;

public class TypeUtils {

    public static int toInt(Object ob) {
        if (ob == null)
            return 0;
        try {
            String s = ob.toString()
                    .replaceAll(" ", "");
            char[] chars = s.toCharArray();
            for (int i = 0; i < chars.length - 1; i++) {
                if ('0' != chars[i]) {
                    return Integer.valueOf(s.substring(i, chars.length));
                }
            }
            return 0;
        } catch (StringIndexOutOfBoundsException e) {
            return 0;
        }
    }

    public static String toStr(Object ob) {
        if (ob == null || ob.toString().equals("N/A"))
            return "";
        return String.valueOf(ob);
    }

    public static boolean isEmptyStr(String s) {
        return TextUtils.isEmpty(s) || s.equals(" ");
    }
}
